package com.vlin.config.tuya;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.vlin.api.client.Client;
import com.vlin.api.client.defaut.DefaultApiPoolClient;
import com.vlin.api.client.defaut.DefaultClient;
import com.vlin.cache.redis.RedisTokenCache;

@Configuration
public class TuyaConfig {

	@Autowired
	private TuyaProperties tuyaProperties;
	
	@Autowired
	private RedisTokenCache tokenCache;
	
	@Bean
	public Client tuyaClient() {
		
		Client client = DefaultClient.build(tuyaProperties.getHost(), tuyaProperties.getApi());
		client.getParamsProducer().setParamsConfig( tuyaProperties.getApi(), tuyaProperties.getParamsConfig());
		client.getTokenManager().setTokenCacheManager(tokenCache);
		client.setApiClient(new DefaultApiPoolClient(5));
		return client;
	}
	
}
